/**
 * 风险评估字典条目规则表管理初始化
 */
var QcEntityDetail = {
	id: "qcEntityDetailTable",	//表格id
	seItem: null,		//选中的条目
	table: null,
	layerIndex: -1,
	depType:"科室",
};
QcEntityDetail.drawTable = function(tableData){
    this.$table =
        $('#qcEntityDetailTable').bootstrapTable({
            data:tableData,
            striped: false,//是否显示行间隔色
            pagination: true,//是否显示分页
            showFooter: false,
            //paginationLoop: false,
            pageSize : 10,//用于设置每页初始显示的条数
            //pageList :[4],
            sidePagination: 'server',//设置在哪进行分页，默认”client”，可选”server”,返回数据模板不同
            sortOrder: 'desc',// desc  asc
            maintainSelected: true,//设为true 为选中的状态
            cache: false,
            search:false, //搜索框
            columns: [
                {title: '病种名', field: 'drgName', align: 'center', width:50,valign: 'middle',sortable: false},
                {title: '入组例数', field: 'inCaseNum', align: 'center', width:50,valign: 'middle',sortable: false,
                    formatter:function(value,row,index) {
                        if (value > 0) {
                            return "<a title='详细' onclick='openQcDetail(&apos;" + row.drgId + "&apos;,&apos;" + row.drgName + "&apos;,&apos;inCaseNum&apos;)'>" + value + "</a>";
                        } else {
                            return 0;
                        }
                    }},
                {title: '质控例数', field: 'qcCaseNum', align: 'center', width:50, valign: 'middle',sortable: false,
                    formatter:function(value,row,index) {
                        if (value > 0) {
                            return "<a title='详细' onclick='openQcDetail(&apos;" + row.drgId + "&apos;,&apos;" + row.drgName + "&apos;,&apos;qcCaseNum&apos;)'>" + value + "</a>";
                        } else {
                            return 0;
                        }
                    }},
                {title: '质控人次', field: 'qcNum', align: 'center', width:70, valign: 'middle',sortable: false},
                {title: '平均住院日', field: 'admDoctorName', align: 'center', width:80,valign: 'middle',sortable: false}
            ],
            onPostHeader: function(){  //当<thead></thead>中的内容被加载完后或者在你所用的DOM中有定义则被触发
                //$(".th-inner").css("font-weight","700");//表头字体加粗
                $("#qcEntityDetailTable > tbody td").each(function(index){//鼠标悬浮 显示表格数据
                    $(this).attr("title",$(this).text());
                });
            }
        });
};
/**
 * 初始化表格的列
 */
QcEntityDetail.initColumn = function () {
	return [
        {title: '病种名', field: 'drgName', align: 'center', width:50,valign: 'middle',sortable: false},
        {title: '入组例数', field: 'inCaseNum', align: 'center', width:50,valign: 'middle',sortable: false,
            formatter:function(value,row,index) {
                if (value > 0) {
                    return "<a title='详细' onclick='openQcDetail(&apos;" + row.drgId + "&apos;,&apos;" + row.drgName + "&apos;,&apos;inCaseNum&apos;)'>" + value + "</a>";
                } else {
                    return 0;
                }
            }},
        {title: '质控例数', field: 'qcCaseNum', align: 'center', width:50, valign: 'middle',sortable: false,
            formatter:function(value,row,index) {
                if (value > 0) {
                    return "<a title='详细' onclick='openQcDetail(&apos;" + row.drgId + "&apos;,&apos;" + row.drgName + "&apos;,&apos;qcCaseNum&apos;)'>" + value + "</a>";
                } else {
                    return 0;
                }
            }},
        {title: '涉及医生', field: 'doctorNum', align: 'center', width:50, valign: 'middle',sortable: false},
        {title: '质控人次', field: 'qcCaseTri', align: 'center', width:50, valign: 'middle',sortable: false},
        {title: '平均住院日', field: 'avgAdmDays', align: 'center', width:50,valign: 'middle',sortable: false}
    ];
};


/**
 * 查询病例
 */
QcEntityDetail.search =function(){
    var params = {};
    params.key = $('#key').val();
    params.office = $("#office").val();
    params.depart = $("#depart").val();
    params.medicalGroup = $("#medicalGroup").val();
    params.drgType = $("#drgType").val();
    params.doctor = $("#doctor").val();

    QcEntityDetail.table.refresh({query: params,pageNumber: 1});
}
function openQcDetail(entityId, entityName, key){
    var index = layer.open({
        type: 2,
        title: ['&nbsp;'+entityName,'padding-left:20px'],
        area: ['90%', '90%'], //宽高
        fix: false, //不固定
        skin:'rbLBStyle  layer-ext-hisui',  //LB为layerBorder缩写
        //maxmin: true,
        content: "/api/departhome/to_case?key="+key+"&depart="+$("#depart").val()+"&medicalGroup="+$("#medicalGroup").val()+"&drgType="
            +entityId+"&doctor="+$("#doctor").val()+"&desc="+entityName
    });
}
$(function () {
    var params = {};
    params.key = $('#key').val();
    params.office = $("#office").val();
    params.depart = $("#depart").val();
    params.medicalGroup = $("#medicalGroup").val();
    params.drgType = $("#drgType").val();
    params.doctor = $("#doctor").val();

    var table = new BSTable(QcEntityDetail.id, "/api/departhome/qcEntityList", QcEntityDetail.initColumn());
    table.setPaginationType("server");
    table.setQueryParams(params);
    table.setShowColumns(false);
    table.setShowRefresh(false);
    table.setShowToggle(false);
    table.setPageSize(15);
    table.setSubHeight(-30);

    QcEntityDetail.table = table.init();
});

